/**
 * field_switch
 */
layui.define(['YunjField','form'], function (exports) {

    let YunjField = layui.YunjField;
    let form = layui.form;

    class YunjSwitch extends YunjField {

        constructor(options={}) {
            super(options);
        }

        defineExtraArgs(){
            let that = this;
            return {
                text:"ON|OFF",
                disabled:false
            };
        }

        layoutControl() {
            let that = this;
            let controlHtml = `<input type="checkbox" name="${that.id}" lay-text="${that.args.text}" } lay-skin="switch" lay-filter="${that.id}" ${that.args.disabled ? 'disabled' : ''}>`;
            return `<div class="layui-input-inline yunj-input-inline yunj-input-pane">${controlHtml}</div>`;
        }

        setValue(val=''){
            let that=this;
            that.fieldBoxEl.find(`input:checkbox[name=${that.id}]`).prop('checked', !!val);
            form.render('checkbox', that.tabFormFilter);
        }

        getValue(){
            let that=this;
            return that.fieldBoxEl.find(`input:checkbox[name=${that.id}]`).is(':checked');
        }

        renderDone(){
            let that = this;
            form.render('checkbox', that.tabFormFilter);
        }

    }

    exports('field_switch', YunjSwitch);
});